package com.shengzai

import scala.io.{BufferedSource, Source}

object Code39Example03 {
  //取总分排名前10的学生

  def main(args: Array[String]): Unit = {
    val listScore: List[String] = Source.fromFile("hadoop_code/src/data/score.txt").getLines().toList
    listScore.map(
      line => {
        val scoreSplit: Array[String] = line.split(",")
        val sid: String = scoreSplit(0)
        val score: Int = scoreSplit.last.toInt
        (sid, score)
      }
    ).groupBy(_._1).map(
      (tuple2) => {
        var sum: Int = 0
        for (elem <- tuple2._2) {
          sum +=elem._2
        }
        (tuple2._1,sum)
      }
    ).toList.sortBy(
      - _._2
    ).take(10).map {
      case (sid: String, score: Int) =>
        s"$sid\t$score"
    }.foreach(println)

  }


}
